All Objects
Form
Text
OBJECT: Password
A
Password
object is created by using an HTML <INPUT> tag and assigning "password" to the TYPE attribute. When a user then enters a password, an asterisk (*) is displayed for every character entered, thus hiding the value of the password from the view of others. A
Password
object must be defined within an HTML <FORM> tag and the JavaScript runtime engine will then create an entry for it in the
elements
property of the appropriate
Form
object. The
Password
object can then be accessed through this
elements
array by referencing either its element number or name, if a NAME attribute was used in its creation. For example, the following HTML code creates a password field with the name "Pass" and no initial value:
Code:
<input type = "password" name = "pass" value = "" size = 20>
Using javaScript you could then, say, test the value of a user's entry in the password field as in the following example which, if the user's entry matches the value previously stored in the MyPassWord variable, executes a function called AllowEntry.
Code:
if(document.myForm.pass.value == myPassWord)
allowEntry()
NOTE:
If a user alters a password interactively, it can only be evaluated accurately if data-tainting is enabled.
PROPERTIES
defaultValue Property
This property, tainted by default, is a string reflecting the VALUE attribute of a
Password
object. Initially this is
null
(for security reasons) regardless of any value assigned to it. You can override the initial
defaultValue
property at any time by setting it programmatically, although this won't be reflected in the display of the
Password
object.
Syntax:
object.
defaultValue
form Property
This property is a reference to the parent form to which a particular
Password
object belongs.
Syntax:
object.
form
name Property
This property, which is tainted by default, is a string reflecting the NAME attribute of a
Password
object, and can be set at any time, overriding the previous value.
NOTE:
If more than one object on any form share the same NAME attribute, an array of those objects is automatically created.
Syntax:
object.
name
type Property
This property reflects the type of any particular object on a form, and in the case of the
Password
object is always "password".
Syntax:
object.
type
value Property
This property, tainted by default, reflects the value entered into a password field by the user. It can be set programatically at any time, but if a user tries to alter it interactively, it won't be evaluated properly unless data-tainting is enabled. Whether altered or not, the value is at all times displayed as a string of asterisks.
Syntax:
object.
value
METHODS
blur method
This method is used to remove focus from the object.
Syntax:
object.
blur
()
focus method
This method is used to give focus to an object. It can be used to focus on a
Password
object prior to a value being entered, either by the user in the password field, or by JavaScript code programatically.
Syntax:
object.
focus
()
handleEvent method
This method calls the handler for a specified event.
Syntax:
object.
handleEvent
(event)
select method
This method causes the input area of a
Password
object to be selected and the cursor to be positioned ready for user input.
Syntax:
object.
select
()
NOTE:
The
Select
object also inherits the
watch
and
unwatch
methods from the
Object
object.
EVENT HANDLERS
onBlur
EventHandler
This event handler causes JavaScript code to be executed whenever a blur event occurs; i.e. whenever a window, frame or form element loses focus.
Syntax:
onBlur
= "myJavaScriptCode"
onFocus
EventHandler
This event handler executes JavaScript whenever a focus event occurs; i.e. whenever the user focuses on a window, frame or frameset, or inputs to a form element.
Syntax:
onFocus
= "myJavaScriptCode"
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information